package com.example.proxytest.proxy.staticproxy;

import com.example.proxytest.proxy.MyTransaction;
import com.example.proxytest.proxy.PersonService;

/* ━━━━━━佛祖保佑━━━━━━
 *                  ,;,,;
 *                ,;;'(    社
 *      __      ,;;' ' \   会
 *   /'  '\'~~'~' \ /'\.)  主
 * ,;(      )    /  |.     义
 *,;' \    /-.,,(   ) \    码
 *     ) /       ) / )|    农
 *     ||        ||  \)
 *     (_\       (_\
 * ━━━━━━永无BUG━━━━━━
 * @author ：zjq
 * @date ：2020/9/7 14:55
 * @description: TODO
 * @version: V1.0
 * @slogan: 天下风云出我辈，一入代码岁月催
 */
public class PersonServiceProxy implements PersonService {
    //目标类
    private PersonService personService;

    //增强类
    private MyTransaction transaction;

    //利用构造函数将目标类和增强类注入
    public PersonServiceProxy(PersonService personService, MyTransaction transaction) {
        this.personService = personService;
        this.transaction = transaction;
    }

    @Override
    public String savePerson() {
        transaction.beginTransaction();
        personService.savePerson();
        transaction.commit();
        return "success save";
    }

    @Override
    public void updatePerson() {
        transaction.beginTransaction();
        personService.updatePerson();
        transaction.commit();
        savePerson();
    }

    @Override
    public void deletePerson() {
        transaction.beginTransaction();
        personService.deletePerson();
        transaction.commit();
    }

}
